using Senparc.Weixin.Entities;
using Senparc.Weixin.HttpUtility;
using Senparc.Weixin.MP.AdvancedAPIs.User;
using Senparc.Weixin.MP.CommonAPIs;
using System;
using System.Collections.Generic;
namespace Senparc.Weixin.MP.AdvancedAPIs
{
	public static class UserApi
	{
		public static UserInfoJson Info(string accessTokenOrAppId, string openId, Language lang = Language.zh_CN)
		{
			return ApiHandlerWapper.TryCommonApi<UserInfoJson>(delegate(string accessToken)
			{
				string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang={2}", accessToken, openId, lang.ToString());
				return Senparc.Weixin.HttpUtility.Get.GetJson<UserInfoJson>(url, null);
			}, accessTokenOrAppId, true);
		}
		public static OpenIdResultJson Get(string accessTokenOrAppId, string nextOpenId)
		{
			return ApiHandlerWapper.TryCommonApi<OpenIdResultJson>(delegate(string accessToken)
			{
				string text = string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}", accessToken);
				if (!string.IsNullOrEmpty(nextOpenId))
				{
					text = text + "&next_openid=" + nextOpenId;
				}
				return Senparc.Weixin.HttpUtility.Get.GetJson<OpenIdResultJson>(text, null);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult UpdateRemark(string accessTokenOrAppId, string openId, string remark, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token={0}", accessToken);
				var data = new
				{
					openid = openId,
					remark = remark
				};
				return CommonJsonSend.Send(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut);
			}, accessTokenOrAppId, true);
		}
		public static BatchGetUserInfoJson BatchGetUserInfo(string accessTokenOrAppId, List<BatchGetUserInfoData> userList, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<BatchGetUserInfoJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token={0}", accessToken);
				var data = new
				{
					user_list = userList
				};
				return CommonJsonSend.Send<BatchGetUserInfoJson>(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
	}
}
